import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import {
	storage
} from "@/common/utils/storage.js"
import store from "@/store/index.js"

//初始化
const router = createRouter({
	platform: '',
	routes: ROUTES
});


// [ 'orderList', 'rentPublic', 'housePublic', 'itemDetail','businessCenter', 'lesseeDetail', 'lesseeList', 'lesseeCheckin', 'addrList', 'paywayList', 'wallet', 'myVipCart', 'myCoupon', 'qrCode'] //路由黑名单

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	const needCheckList = store.state.clientInfo.needCheckList || []
	// console.log('前置守卫----------', from, to)
	if (storage.isLogin()) {
		if (to.name == 'login' || to.name == 'authLogin') {
			
		}
		//监听点击后，跳转前的事件，并做处理
		if (to.name == 'custodyList') {
			
		} else {
			next()
		}
	} else {
		if (needCheckList.indexOf(to.name) != -1 && from.name != 'login' && from.name != 'authLogin') {
			//不需要登录成功之后跳转到目标界面的，在这里做判断
			var toName = to.name
			var query = to.query
			// #ifdef APP-PLUS
			next({
				name: 'login',
				params: {
					toName: toName,
					query: query
				}
			})
			// #endif
			// #ifndef APP-PLUS
			next({
				name: 'login',
				params: {
					toName: toName,
					query: query
				}
			})
			// #endif
		} else {
			next()
		}
	}
})

// 全局路由后置守卫
router.afterEach((to, from) => {})

function toLogin(params) {
	// #ifdef APP-PLUS
	router.push({
		name: 'login',
		params: params
	})
	// #endif
	// #ifndef APP-PLUS
	router.push({
		name: 'login',
		params: params
	})
	// #endif
}

export {
	router,
	RouterMount,
	toLogin
}
